<template>
  <div>
    <!-- 表头 -->
    <div class="heade">
      <div class="kuang" @click="SouFn">
        <div class="hez">
          <i class="iconfont icon-search"></i>
          卫生纸
        </div>
      </div>
      <div class="right-classify iconfont icon-ellipsis"></div>
    </div>
    <!-- left -->
    <div class="lefts">
      <div class="fenlei">
        <ul class="ulis">
          <li
            v-for="(item,i) in yijiarr"
            :key="i"
            :data-cla="i"
            ref="listItem"
            :class="{'active':(i+1)==index}"
            @click="tabFn(item,i)"
          >{{item.title}}</li>
        </ul>
      </div>
    </div>
    <!-- right -->
    <div class="rights">
      <div class="shangpin">
        <ul class="uli">
          <li class="lis" v-for="(item,i) in sanjiarr" :key="i" @click="fenleiFn">
            <div class="jinkou icon">{{item.title}}</div>
            <div class="lbp">
              <ul class="ulists">
                <li>
                  <img src="../assets/shuangfushui.jpg" alt />
                  <div>进口乳液/面霜</div>
                </li>
              </ul>
            </div>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      yijiarr: [],
      erjiarr: [],
      sanjiarr: [],
      index: 0
    };
  },
  mounted() {
    this.index = 1;
    this.getData();
    console.log(this.erjiarr);
  },
  methods: {
    //跳转分类页面
    fenleiFn() {
      this.$router.push("/classifySon");
    },
    //跳转搜索页面
    SouFn() {
      this.$router.push("/detial");
    },
    //tab切换
    tabFn(item, i) {
      this.index = i + 1;
      let guolv = this.erjiarr.filter(res => {
        return item.title == res.belong;
      });
      this.sanjiarr = guolv;
      this.getData();
      console.log(guolv);
    },
    //获取数据
    getData() {
      axios({
        url: "http://localhost/api.php/like/phonetype",
        method: "get",
        params: {
          transform: 1
        }
      }).then(res => {
        console.log(res);
        //过滤一级菜单
        let yiji = res.data.phonetype.filter(res => {
          return res.leve == 1;
        });
        this.yijiarr = yiji;
        //过滤二级菜单
        let erji = res.data.phonetype.filter((res, index) => {
          return res.leve == 2;
        });
        this.erjiarr = erji;
      });
    }
  }
};
</script>

<style>
.ulists {
  margin-top: 0.2rem;
}
.ulists li img {
  width: 100% !important;
  vertical-align: middle;
}
.ulists li {
  text-align: center;
  background: #fff;
  font-size: 0.2rem;
  position: relative;
  display: inline-block;
  margin-bottom: 0.1rem;
  width: 30%;
  vertical-align: top;
  color: #666;
}
.uli li .icon {
  color: #999;
  font-size: 0.2rem;
  border-left: 2px solid #fe5b4a;
  padding-left: 0.1rem;
  line-height: 1;
}
.uli .lis {
  padding: 0.2rem 0.1rem;
}
.rights {
  position: absolute;
  overflow: hidden;
  left: 1.64rem;
  right: 0;
  bottom: 0;
  top: 0.8rem;
  z-index: 9;
  background: white;
  overflow-y: auto;
}
.lefts {
  width: 1.65rem;
  position: absolute;
  top: 0.79rem;
  bottom: 0;
  z-index: 10;
  overflow-y: auto;
}
.ulis li {
  line-height: 0.75rem;
  font-size: 0.24rem;
  text-align: center;
  background: #eee;
  border-right: 1px solid #ddd;
  border-bottom: 1px solid #ddd;
}
.ulis .active {
  border-left: 5px solid #fe5b4a !important;
  border-right: 1px solid #fff;
  background-color: #fff;
}
.right-classify {
  font-size: 0.5rem;
}
.hez {
  font-size: 0.2rem;
  display: flex;
  align-items: center;
}
.kuang {
  background: #fff;
  padding: 0.1rem 0.1rem;
  width: 5rem;
  border: 1px solid #ddd;
  border-radius: 5px;
}
.kuang i {
  color: #a1a1a1;
  font-size: 0.3rem;
  margin-right: 0.1rem;
}
.heade {
  border-color: #ddd;
  background-color: #f5f5f5;
  color: #444;
  padding: 0.1rem 0.2rem;
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid #ddd;
}
</style>